package com.leyou.controller;

import com.leyou.search.service.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping
public class UploadController {

    @Autowired
    private UploadService uploadService;

    /**
     * 上传图片，然后返回图片的url
     */
    @PostMapping("/image")
    public ResponseEntity<String> uploadImage(@RequestParam("file")MultipartFile file){
        /*返回200，并携带url路径*/
        return ResponseEntity.ok(uploadService.upload(file));
    }

    /**
     * 获取阿里上传文件所需要的信息
     * @return
     */
    @GetMapping("/signature")
    public ResponseEntity<Map<String,Object>> getAliSignature(){
        return ResponseEntity.ok(uploadService.getSignature());
    }

}
